﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Space.CoreTypes
{
    /// <summary>
    /// This class represents a numeric vector.
    /// </summary>
    [Serializable]
    public class SpaceVector : ISpaceEntry
    {
        /// <summary>
        /// The specified vector data.
        /// </summary>
        [SpaceAttribute] 
        private readonly double[] data;

        /// <summary>
        /// Initializes a new instance of the <see cref="SpaceVector"/> class.
        /// </summary>
        /// <param name="components">The number of components of the vector.</param>
        public SpaceVector(int components)
        {
            this.data = new double[components];
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SpaceVector"/> class.
        /// </summary>
        /// <param name="data">The specified vector data.</param>
        public SpaceVector(double[] data)
        {
            this.data = (double[]) data.Clone();
        }

        /// <summary>
        /// Gets the number of components of the vector.
        /// </summary>
        /// <value>The number of components of the vector.</value>
        public int Count
        {
            get { return this.data.Length; }
        }

        /// <summary>
        /// Gets or sets the <see cref="System.Double"/> at the specified index.
        /// </summary>
        /// <value>The value of the vector at the specified position.</value>
        public double this[int index]
        {
            get { return this.data[index]; }
            set { this.data[index] = value; }
        }

        /// <summary>
        /// Converts the current space type to a <see cref="SmartMathLibrary.GeneralVector"/>.
        /// </summary>
        /// <returns>The converted vector.</returns>
        public GeneralVector ToVector()
        {
            return new GeneralVector((double[])this.data.Clone());
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object Clone()
        {
            return CloneFunctions.Clone(this);
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the object instances are even, the method returns true otherwise, false.
        /// </returns>
        public bool Equals(ISpaceEntry entry)
        {
            if (entry is SpaceVector)
            {
                SpaceVector check = (SpaceVector)entry;

                if (this.Count == check.Count)
                {
                    for (int i=0;i <this.Count;i++)
                    {
                        if (this[i]!=check[i])
                        {
                            return false;
                        }
                    }

                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the specified object instance is lower than the current instance the method returns true otherwise,
        /// false.
        /// </returns>
        public bool LowerThan(ISpaceEntry entry)
        {
            return false;
        }

        /// <summary>
        /// Compares the current <see cref="ISpaceEntry"/> to the specified <see cref="ISpaceEntry"/>.
        /// </summary>
        /// <param name="entry">The specified entry to compare.</param>
        /// <returns>
        /// If the specified object instance is greater than the current instance the method returns true otherwise,
        /// false.
        /// </returns>
        public bool GreaterThan(ISpaceEntry entry)
        {
            return false;
        }
    }
}